package com.zou.dataStruct;

import com.zou.dataStruct.Array.Array;
import com.zou.dataStruct.Array.ArrayQueue;
import com.zou.dataStruct.Array.ArrayStack;
import com.zou.dataStruct.Array.LoopQueue;
import org.junit.Test;

import java.util.LinkedList;

public class MainClas {

    public static void main(String[] args) {
/*        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        System.out.println(a);*/
        String url1 = MainClas.class.getClassLoader().getResource("").toString();
        String url2 = MainClas.class.getResource("/").toString(); //项目根路径
        String url4 = MainClas.class.getResource("/").getFile(); //项目根路径
        String url3 = MainClas.class.getResource("").toString();//文件根路径
        System.out.println(url1);
        System.out.println(url2);
        System.out.println(url3);
        System.out.println(url4);


    }

    @Test
    public void ArrayTest() {
        Array<Integer> array = new Array<>();
        array.addFirst(8);
        array.add(1, 4);
        array.add(2, 2);
        array.add(3, 1);
        array.remove(3);
        System.out.println(array);
    }

    @Test
    public void StackTest() {
        ArrayStack<Integer> stack = new ArrayStack<>();
        for (int i = 0; i < 6; i++) {
            stack.push(i);
            System.out.println(stack);
        }
        stack.pop();
        stack.pop();
        stack.pop();
        System.out.println(stack);
    }

    @Test
    public void QueueTest() {
        ArrayQueue<Integer> queue = new ArrayQueue<>();
        for (int i = 0; i < 10; i++) {
            queue.enqueue(i);
            System.out.println(queue);
            if (i % 3 == 2) {
                queue.dequeue();
                System.out.println(queue);
            }
        }
    }

    @Test
    public void LoopQueueTest() {
        LoopQueue<Integer> queue = new LoopQueue<>();
        for (int i = 0; i < 10; i++) {
            queue.enqueue(i);
            System.out.println(queue);
            if (i % 3 == 2) {
                queue.dequeue();
                System.out.println(queue);
            }
        }
    }

    @Test
    public void LinkedListTest(){
        LinkedList<Integer> lk = new LinkedList<>();
        for(int i=0;i<10;i++){
            //lk.addFirst(i);
            lk.add(i,i);
        }
        System.out.println(lk);
    }

    @Test
    public void fff(){
        String str = "120000314003052,120000314003057,120000314003055," +
                "120000314003061,120000314003001,120000314003004,120000314003005," +
                "120000314003003,120000314003009,120000314003013,120000314003006,120000314003008," +
                "120000314003007,120000314003014,120000314003010";
        System.out.println(serialNumberList(str));
    }

    private static String serialNumberList(String serialNumber) {
        StringBuffer sb = new StringBuffer();
        String[] split = serialNumber.split("[,]");
        int size = split.length;
        for (int i = 0; i < size; i++) {
            if (i != size - 1) {
                sb.append(split[i] + ",");
            } else {
                sb.append(split[i]);
            }
            if ((i + 1) % 4 == 0) {
                sb.append("<br/>");
            }
        }

        return sb.toString();
    }

}
